package ar.edu.unrn.lia.bean.convert;

import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import ar.edu.unrn.lia.model.Garante;
import ar.edu.unrn.lia.service.GaranteService;
import ar.edu.unrn.lia.service.InquilinoService;

@ManagedBean(name = "garanteConvert")
@RequestScoped
public class GaranteConvert implements Converter {

	@ManagedProperty(value = "#{garanteService}")
	GaranteService garanteService;

	@Override
	public Object getAsObject(FacesContext ctx, UIComponent comp, String value) {

		if (value == null) {
			return null;
		}

		return getGaranteService().getEntityById(Long.parseLong(value));
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
		return value instanceof Garante ? ((Garante) value).getId()
				.toString() : "";
	}

	public GaranteService getGaranteService() {
		return garanteService;
	}

	public void setGaranteService(GaranteService garanteService) {
		this.garanteService = garanteService;
	}

	

}
